package com.sunlands.zlcx.usercenter.vo;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.sunlands.zlcx.usercenter.constant.YN;
import com.sunlands.zlcx.usercenter.domain.UsersTargetRelationDO;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import java.util.Objects;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class UsersTargetRelationVO implements Serializable {

    private static final long serialVersionUID = 2527339972803213560L;
    private Long id;
    /**
     * 目标id
     */
    @ApiModelProperty(value = "目标id")
    private Long targetId;

    /**
     * 目标名称
     */
    @ApiModelProperty(position = 10, value = "目标名称")
    private String targetName;

    /**
     * 用户id
     */
    @ApiModelProperty(value = "用户id")
    private Long userId;

    /**
     * 用户名称
     */
    @ApiModelProperty(value = "用户名称")
    private String userName;

    /**
     * {@link YN}
     * 状态
     */
    @ApiModelProperty(value = "状态")
    private Integer status;

    /**
     * 创建时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    @ApiModelProperty(value = "开始时间")
    private Date startTime;

    /**
     * 结束时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    @ApiModelProperty(value = "结束时间")
    private Date endTime;

    /**
     * 学习时长
     */
    @ApiModelProperty(value = "学习时长")
    private BigDecimal studyHours;

    /**
     * 修改时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    private Date updateTime;

    /**
     * 创建时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    private Date createTime;


    public static UsersTargetRelationVO from(UsersTargetRelationDO usersTargetRelationDO) {
        return Objects.isNull(usersTargetRelationDO)? null : UsersTargetRelationVO.builder().id(usersTargetRelationDO.getId())
                .createTime(usersTargetRelationDO.getCreateTime())
                .updateTime(usersTargetRelationDO.getUpdateTime())
                .status(usersTargetRelationDO.getStatus())
                .targetId(usersTargetRelationDO.getTargetId())
                .targetName(usersTargetRelationDO.getTargetName())
                .userId(usersTargetRelationDO.getUserId())
                .userName(usersTargetRelationDO.getUserName())
                .endTime(usersTargetRelationDO.getEndTime())
                .studyHours(usersTargetRelationDO.getStudyHours())
                .startTime(usersTargetRelationDO.getCreateTime())
                .build();
    }
}
